//
//  FYHMenuViewController.m
//  FollowYourHeart
//
//  Created by lanou3g on 16/3/11.
//  Copyright © 2016年 李晨玲. All rights reserved.
//

#import "FYHMenuViewController.h"
#import "AppDelegate.h"
#import "UIColor.h"
#import "FYHIndexViewController.h"

@interface FYHMenuViewController ()
{
    UIButton *loginOrRegisterButton;
    UIButton *indexButton;
    UIButton *seachWorldButton;
    UIButton *TravelNotesButton;
    UIButton *SettingsButton;
    UIButton *ToolButton;
    NSInteger buttonSelect;
}
@property (strong, nonatomic)UIImageView *headerImv;


@end

@implementation FYHMenuViewController

enum
{
    loginOrRegister = 0,
    indexb,
    seachWorld,
    travelNotes,
    settings,
    tool
    
};
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setViews];
}

//设置视图
- (void)setViews{
    //背景
    UIImageView *backgroundImv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight + 64)];
    backgroundImv.image = [UIImage imageNamed:@"meunBackground.jpg"];
    backgroundImv.userInteractionEnabled = YES;
    [self.view addSubview:backgroundImv];
    //毛玻璃效果
    UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect];
    view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight + 64);
    view.userInteractionEnabled = YES;
    //    [backgroundImv addSubview:view];
    
    //头像
    self.headerImv = [[UIImageView alloc] initWithFrame:CGRectMake(250 / 2 - 35, 100, 70, 70)];
    self.headerImv.backgroundColor = [UIColor whiteColor];
    self.headerImv.layer.cornerRadius = self.headerImv.frame.size.width / 2;
    self.headerImv.layer.masksToBounds = YES;
    self.headerImv.image = [UIImage imageNamed:@"default.png"];
    self.headerImv.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loginOrRegisterAction)];
    [self.headerImv addGestureRecognizer:tap];
    [self.view addSubview:self.headerImv];
    
    //登陆注册
    loginOrRegisterButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame), CGRectGetMaxY(self.headerImv.frame) + 10, 70, 30)];
    [loginOrRegisterButton setTitle:@"登录/注册" forState:(UIControlStateNormal)];
    loginOrRegisterButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [loginOrRegisterButton addTarget:self action:@selector(loginOrRegisterAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:loginOrRegisterButton];
    
    //首页
    indexButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame) - 10, CGRectGetMaxY(loginOrRegisterButton.frame) + 10, 100, 30)];
    [indexButton setTitle:@"首页" forState:(UIControlStateNormal)];
    indexButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [indexButton addTarget:self action:@selector(indexAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:indexButton];
    
    
    //世界探索
    seachWorldButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame) - 10, CGRectGetMaxY(indexButton.frame) + 10, 100, 30)];
    [seachWorldButton setTitle:@"世界探索" forState:(UIControlStateNormal)];
    [seachWorldButton setTitleColor:[UIColor blackColor] forState:(UIControlStateSelected)];
    seachWorldButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [seachWorldButton addTarget:self action:@selector(seachWorldAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:seachWorldButton];
    
    //游记
    TravelNotesButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame) - 10, CGRectGetMaxY(seachWorldButton.frame) + 10, 100, 30)];
    [TravelNotesButton setTitle:@"游记" forState:(UIControlStateNormal)];
    TravelNotesButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [TravelNotesButton addTarget:self action:@selector(travelNotesAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:TravelNotesButton];
    
    //设置
    SettingsButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame) - 10, CGRectGetMaxY(TravelNotesButton.frame) + 10, 100, 30)];
    SettingsButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [SettingsButton setTitle:@"设置" forState:(UIControlStateNormal)];
    [SettingsButton addTarget:self action:@selector(settingsAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:SettingsButton];
    
    //工具
    ToolButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.headerImv.frame) - 10, CGRectGetMaxY(SettingsButton.frame) + 10, 100, 30)];
    ToolButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [ToolButton setTitle:@"工具" forState:(UIControlStateNormal)];
    [ToolButton addTarget:self action:@selector(toolAction) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:ToolButton];

    
}
//登陆注册页面
- (void)loginOrRegisterAction{
    buttonSelect = 0;
    [self buttonChange];
   
    
}

//首页
- (void)indexAction {
    buttonSelect = 1;
    [self buttonChange];
    FYHIndexViewController *indexVC = [FYHIndexViewController new];
    UINavigationController *indexNav = [[UINavigationController alloc] initWithRootViewController:indexVC];
    
    // 设置根视图控制器
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    [app.drawer setRootViewController:indexNav];
    
}

//世界探页面
- (void)seachWorldAction {
    buttonSelect = 2;
    [self buttonChange];
    
}

//游记页面
- (void)travelNotesAction{
    buttonSelect = 3;
    [self buttonChange];
   
    
}

//设置页面
- (void)settingsAction{
    buttonSelect = 4;
    [self buttonChange];
    
    
}

//工具
- (void)toolAction{
    buttonSelect = 5;
    [self buttonChange];
    
    
}

//按钮的变换
- (void)buttonChange{
    [indexButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    [seachWorldButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    [TravelNotesButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    [SettingsButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    [loginOrRegisterButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    [ToolButton setTitleColor:[UIColor colorWithHex:0xFFFFFF] forState:(UIControlStateNormal)];
    switch (buttonSelect) {
        case loginOrRegister:{
            [loginOrRegisterButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        case indexb:{
            [indexButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        }
        case seachWorld:{
            [seachWorldButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        }
        case travelNotes:{
            [TravelNotesButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        }
        case settings:{
            [SettingsButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        }
        case tool:{
            [ToolButton setTitleColor:[UIColor colorWithHex:0x11d4a6] forState:(UIControlStateNormal)];
            break;
        }

        }
        default:
            break;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
